package com.example.tests;

import static org.hamcrest.Matchers.*;
import static org.hamcrest.MatcherAssert.*;

import java.util.Random;

import org.testng.annotations.Test;

import com.example.obj.FolderList;

public class Test_01_FolderCreation extends TestBase{
	
	Random rnd = new Random();
	
	@Test(priority = 1)
	public void testFolderCanBeCreated() throws Exception {
		log.info("Start testFolderCanBeCreated");
		String folder = "FolderName" + rnd.nextInt();		
		FolderList oldFolderList = manager.getFolderHelper().getFolders();
		log.info("Old folder list: " + oldFolderList);
		assertThat(manager.getFolderHelper().createFolder(folder), is(nullValue()));
		FolderList newFolderList = manager.getFolderHelper().getFolders();
		log.info("New folder list: " + newFolderList);
		log.info("Start assertions: size, lists' elements");
		assertThat(newFolderList.size(), equalTo(oldFolderList.size() + 1));
		assertThat(newFolderList, equalTo(oldFolderList.with(folder)));
		log.info("Stop assertions");
	}

	@Test
	public void testTwoDiffFoldersCanBeCreated() throws Exception {
		log.info("Start testTwoDiffFoldersCanBeCreated");
		String[] folders = {"FolderName" + rnd.nextInt(), "FolderName"  + rnd.nextInt()};
		FolderList oldFolderList = manager.getFolderHelper().getFolders();
		log.info("Old folder list: " + oldFolderList);
		assertThat(manager.getFolderHelper().createFolder(folders[0]), is(nullValue()));
		FolderList newFolderList = manager.getFolderHelper().getFolders();
		log.info("New folder list: " + newFolderList);		
		log.info("Start assertions: size, lists' elements");
		assertThat(newFolderList.size(), equalTo(oldFolderList.size() + 1));
		assertThat(newFolderList, equalTo(oldFolderList.with(folders[0])));
		log.info("Stop assertions");
		assertThat(manager.getFolderHelper().createFolder(folders[1]), is(nullValue()));
		FolderList newFolderList2 = manager.getFolderHelper().getFolders();
		log.info("New folder list2: " + newFolderList2);	
		log.info("Start assertions: size, lists' elements");
		assertThat(newFolderList2.size(), equalTo(newFolderList.size() + 1));
		assertThat(newFolderList2, equalTo(newFolderList.with(folders[1])));
		log.info("Stop assertions");	
	}
	
	@Test
	public void testTwoIdentFoldersCanBeCreated() throws Exception {
		log.info("Start testTwoIdentFoldersCanBeCreated");
		String folder = "FolderName" +  + rnd.nextInt();		
		FolderList oldFolderList = manager.getFolderHelper().getFolders();
		log.info("Old folder list: " + oldFolderList);
		assertThat(manager.getFolderHelper().createFolder(folder), is(nullValue()));
		FolderList newFolderList = manager.getFolderHelper().getFolders();
		log.info("New folder list: " + newFolderList);		
		log.info("Start assertions: size, lists' elements");
		assertThat(newFolderList.size(), equalTo(oldFolderList.size() + 1));
		assertThat(newFolderList, equalTo(oldFolderList.with(folder)));
		log.info("Stop assertions");
		assertThat(manager.getFolderHelper().createFolder(folder), containsString("Duplicated folder name"));
		FolderList newFolderList2 = manager.getFolderHelper().getFolders();
		log.info("New folder list2: " + newFolderList2);	
		log.info("Start assertions: size, lists' elements");
		assertThat(newFolderList2.size(), equalTo(newFolderList.size()));
		assertThat(newFolderList2, equalTo(newFolderList));
		log.info("Stop assertions");	
	}
}
